package com.newlink.building.record.adapter

import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.newlink.building.common_base.model.bean.SecurityRecordListData
import com.newlink.building.record.R

/**
 * @author wangyang
 * @date 2022/9/29
 * @description 安防记录的Adapter
 */
class Module_Record_SecurityRecordAdapter(data: MutableList<SecurityRecordListData>) :
    BaseQuickAdapter<SecurityRecordListData, BaseViewHolder>(
        R.layout.item_security_record, data
    ), LoadMoreModule {

    init {
        addChildClickViewIds(R.id.iv_preview)
    }

    override fun convert(holder: BaseViewHolder, item: SecurityRecordListData) {
        holder.setText(R.id.tv_name, item.devName)
        holder.setText(R.id.tv_time, item.alarmTime)
        when (item.alarmType) {
            1 -> {
                // 防拆单独拿出来
                holder.setText(R.id.tv_describe, context.getString(R.string.alarm_type_tamper))
            }

            2 -> {
                holder.setText(
                    R.id.tv_describe,
                    context.getString(R.string.function_move_detection)
                )
            }

            else -> {
                holder.setText(R.id.tv_describe, item.alarmDesc)
            }
        }
        Glide.with(context).load(item.fileUrl).centerCrop()
            .placeholder(R.drawable.default_screenshot).into(holder.getView(R.id.iv_preview))
        holder.setVisible(R.id.iv_preview, item.fileUrl.isNotEmpty())

        if (item.handle == 1) {
            //已处理
            holder.setBackgroundResource(R.id.iv_status, R.drawable.shape_read_message)
        } else {
            //未处理
            holder.setBackgroundResource(R.id.iv_status, R.drawable.shape_unread_message)
        }
    }
}